package com.hsu.hsurpc.protocal;

import lombok.Getter;

/**
 * 协议消息的状态枚举
 * @Author Hsu琛君珩
 * @Date 2024-09-23 10:14
 * @Description
 * @Version: v1.0.0
 */
@Getter
public enum ProtocolMessageStatusEnum {

    OK("ok", 20),
    BAD_REQUEST("badRequest", 40),
    BAD_RESPONSE("badResponse", 50);

    private final String text;
    private final int value;

    ProtocolMessageStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据状态码获取对应枚举
     *
     * @param value 状态码
     * @return 对应的状态枚举
     */
    public static ProtocolMessageStatusEnum getEnumByValue(int value) {
        for (ProtocolMessageStatusEnum anEnum : ProtocolMessageStatusEnum.values()) {
            if (anEnum.value == value) {
                return anEnum;
            }
        }
        return null;
    }
}
